<?php

namespace App\Api\Controllers;

use App\Api\Dao\OrderDao;
use App\Api\Dao\UserAddressDao;
use App\Api\Dao\UserAreaLogDao;
use App\Api\Dao\UserDao;
use App\Api\Dao\UserProfitDao;
use App\Api\Logic\UserAddressLogic;
use App\Api\Logic\UserLogic;
use App\Exceptions\DaoException;
use App\Exceptions\ValidationException;
use Illuminate\Http\Request;

class UserController extends BaseController
{
    /**
     * 用户注册
     * @param Request $request
     * @param UserLogic $userLogic
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ValidationException
     */
    public function userRegister(Request $request,UserLogic $userLogic,UserDao $userDao){
        $params = $request->post();

        $userLogic->user_register($params);
        $result = $userDao->user_register($params);
        return $this->success($result);
    }

    /**
     * 用户登录
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     */
    public function userLogin(Request $request,UserLogic $userLogic,UserDao $userDao){
        $data = $request->all();
        $userLogic->userLogin($data);
        $result = $userDao->userLogin($data);
        return $this->success($result);
    }

    /**
     * 获取用户的个人信息
     * @return \Illuminate\Http\JsonResponse
     */
    public function getUser(Request $request,UserDao $userDao){
        $result = $userDao->get_user(['id'=>$request->u_id]);
        return $this->success($result);
    }

    /**
     * 添加收获地址
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     * @throws DaoException
     */
    public function addAddress(Request $request,UserAddressLogic $userAddressLogic,UserAddressDao $userAddressDao){
        $params = $request->all();
        $params = array_merge(['u_id'=>$request->u_id],$params);
        $userAddressLogic->addAddress($params);
        $result = $userAddressDao->addAddress($params);
        return $this->success($result);
    }


    /**
     * 获取收获地址
     * @return \Illuminate\Http\JsonResponse
     */
    public function getAddress(Request $request,UserAddressDao $userAddressDao){
        $result = $userAddressDao->getAddress(['u_id'=>$request->u_id]);
        return $this->success($result);
    }

    /**
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     * @throws DaoException
     */
    public function delAddress(Request $request,UserAddressLogic $userAddressLogic,UserAddressDao $userAddressDao){
        $params = $request->all();
        $params = array_merge(['u_id'=>$request->u_id],$params);
        $userAddressLogic->delAddress($params);
        $result = $userAddressDao->delAddress($params);
        return $this->success($result);
    }

    /**
     * 获取收获地址详情
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     */
    public function getAddressInfo(Request $request,UserAddressLogic $userAddressLogic,UserAddressDao $userAddressDao){
        $params = $request->all();
        $params = array_merge(['u_id'=>$request->u_id],$params);
        $userAddressLogic->getAddressInfo($params);
        $result = $userAddressDao->getAddressInfo($params);
        return $this->success($result);
    }

    /**
     *设置支付密码
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     * @throws DaoException
     */
    public function setPayPassword(Request $request,UserLogic $userLogic,UserDao $userDao){
        $data = array_merge(['u_id'=>$request->u_id],$request->all());
        $userLogic->setPayPassword($data);
        $result = $userDao->setPayPassword($data);
        return $this->success($result);
    }

    /**
     * 获取用户的分享吗
     * @return false|\Illuminate\Http\JsonResponse|string
     * @throws ValidationException
     * @throws DaoException
     */
    public function getUserSharePic(Request $request,UserLogic $userLogic,UserDao $userDao){
        $data = array_merge(['u_id'=>$request->u_id],$request->all());
        //$userLogic->getUserSharePic($data);
        $result = $userDao->getUserSharePic($data);
        return $this->success($result);
    }

    /**
     * 获取我的好友
     * @return \Illuminate\Http\JsonResponse
     */
    public function getChildUser(Request $request,UserLogic $userLogic,UserDao $userDao){
        $data = array_merge(['u_id'=>$request->u_id],$request->all());
        $userLogic->getChildUser($data);
        $result = $userDao->getChildUser($data);
        return $this->success($result);
    }

    /**
     * @param Request $request
     * @param UserLogic $userLogic
     * @param UserDao $userDao
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     */
    public function getChildUserTwo(Request $request,UserLogic $userLogic,UserDao $userDao){
        $data = array_merge(['u_id'=>$request->u_id],$request->all());
        $userLogic->getChildUserTwo($data);
        $result = $userDao->getChildUserTwo($data);
        return $this->success($result);
    }

    /**
     * 获取我的朋友圈
     * @return \Illuminate\Http\JsonResponse
     */
    public function getAllChildUser(Request $request,UserLogic $userLogic,UserDao $userDao){
        $data = array_merge(['u_id'=>$request->u_id],$request->all());
        $userLogic->getAllChildUser($data);
        //$result = $userDao->getAllChildUser($data);
        $result = $userDao->getAllJianUser($data);
        return $this->success($result);
    }

    /**
     * 获取用户的流水
     * @return \Illuminate\Http\JsonResponse
     */
    public function getUserFlow(Request $request,UserLogic $userLogic,UserProfitDao $userProfitDao){
        $data = array_merge(['u_id'=>$request->u_id],$request->all());
        $userLogic->getUserFlow($data);
        $result = $userProfitDao->getUserFlow($data);
        return $this->success($result);
    }

    /**
     * @param Request $request
     * @param UserLogic $userLogic
     * @param UserProfitDao $userProfitDao
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     */
    public function getUserRepeatFlow(Request $request,UserLogic $userLogic,UserProfitDao $userProfitDao){
        $data = array_merge(['u_id'=>$request->u_id],$request->all());
        $userLogic->getUserFlow($data);
        $result = $userProfitDao->getUserRepeatFlow($data);
        return $this->success($result);
    }

    /**
     * 更新用户信息
     * @return \Illuminate\Http\JsonResponse
     */
    public function updateUserInfo(Request $request,UserDao $userDao){
        $data = array_merge(['u_id'=>$request->u_id],$request->all());
        $result = $userDao->updateUserInfo($data);
        return $this->success($result);
    }

    /**
     * 获取好友的信息详情
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     */
    public function getFriendUserInfo(Request $request,UserLogic $userLogic,UserDao $userDao){
        $data = array_merge(['u_id'=>$request->u_id],$request->all());
        $userLogic->getFriendUserInfo($data);
        $data = $userDao->getFriendUserInfo($data);
        return $this->success($data);
    }

    /**
     * 获取好友的订单
     * @param Request $request
     * @param UserLogic $userLogic
     * @param UserDao $userDao
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     */
    public function getFriendUserOrder(Request $request,UserLogic $userLogic,OrderDao $orderDao)
    {
        $data = array_merge(['u_id'=>$request->u_id],$request->all());
        $userLogic->getFriendUserInfo($data);
        $data = $orderDao->getFriendUserOrder($data);
        return $this->success($data);
    }

    /**
     * 修改登录密码
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     */
    public function resetUserPassword(Request $request,UserLogic $userLogic,OrderDao $orderDao)
    {
        $data = $request->all();
        $userLogic->resetUserPassword($data);
        $data = $orderDao->resetUserPassword($data);
        return $this->success($data);
    }

    /**
     * 获取用户的区域
     * @return \Illuminate\Http\JsonResponse
     */
    public function getUserArea(Request $request,UserAreaLogDao $userAreaLogDao){
        $data = array_merge(['u_id'=>$request->u_id],$request->all());
        $data = $userAreaLogDao->getUserArea($data);
        return $this->success($data);
    }

}
